package com.agilegroup.crm.adapters;

import java.text.SimpleDateFormat;
import java.util.List;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.agilegroup.crm.R;
import com.agilegroup.crm.model.CallData;

/**
 * @author Hisham
 *
 */
@SuppressLint("SimpleDateFormat")
public class CallAdapter extends BaseAdapter{

	private Context context;
	private List<CallData> callData;
	public CallAdapter(Context context, List<CallData> callData) {
		this.callData=callData;
		this.context=context;
	}
	public int getCount() {
		return callData.size();
	}

	public Object getItem(int position) {
		return callData.get(position);
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
        if (v == null)
        {
           LayoutInflater vi = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
           v = vi.inflate(R.layout.event_row, null);
           
           TextView id = (TextView)v.findViewById(R.id.txtid);
           TextView startTime = (TextView)v.findViewById(R.id.txtstartTime);
           TextView endTime = (TextView)v.findViewById(R.id.txtEndTime);
           TextView date = (TextView)v.findViewById(R.id.txtDate);
           TextView contactedPerson = (TextView)v.findViewById(R.id.txtContactedPerson);
           TextView lblContactedBy = (TextView)v.findViewById(R.id.lblContactedBy);
           TextView contactedBy = (TextView)v.findViewById(R.id.txtContactedBy);
           
           CallData data = new CallData();
           data=callData.get(position);
           id.setText(data.getId().toString());
           startTime.setText(data.getStartTime());
           endTime.setText(data.getEndTime());
           if(data.getDate()!=null){
        	   SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
               String formattedDate = formatter.format(data.getDate());          
               date.setText(formattedDate);
           }
           
           
           contactedPerson.setText(data.getContactedPersonName());
           lblContactedBy.setText(R.string.lblCRMStaff);
           contactedBy.setText(data.getCrmStaffName());
        }
        return v;
	}

}
